package com.imooc.spring.jdbc.entity;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 员工实体类
 */
public class Employee {
    private Integer eno;
    private String ename;
    private Float salary;
    private String dname;
    private Date hireDate;


    /**
     * 1、具备默认的构造函数
     * 2、属性私有
     * 3、存在getter与setter
     */
    public Employee() {

    }

    public Employee(Integer eno, String ename, Float salary, String dname) {
        setEno(eno);
        setEname(ename);
        setSalary(salary);
        setDname(dname);
    }

    public Integer getEno() {
        return eno;
    }

    public void setEno(Integer eno) {
        this.eno = eno;
    }

    public String getEname() {
        return ename;
    }

    public void setEname(String ename) {
        this.ename = ename;
    }

    public Float getSalary() {
        return salary;
    }

    public void setSalary(Float salary) {
        this.salary = salary;
    }

    public String getDname() {
        return dname;
    }

    public void setDname(String dname) {
        this.dname = dname;
    }

    public Date getHireDate() {
        return hireDate;
    }

    public void setHireDate(Date hireDate) {
        //转换为日期格式
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String date = sdf.format(hireDate);
        //将字符串转换为日期格式
        try {
            this.hireDate = sdf.parse(date);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public String toString() {
        return "Employee{" +
                "eno=" + eno +
                ", ename='" + ename + '\'' +
                ", salary=" + salary +
                ", dname='" + dname + '\'' +
                ", hiredate=" + hireDate +
                '}';
    }
}
